#include <iostream>
#include <vector>
#include <unordered_map>

bool checkParentheses(std::string rak) {
    std::vector<char> stack;
    std::vector<char> opening = {'(', '[', '{'};
    std::vector<char> closing = {')', ']', '}'};
    std::unordered_map<char, char> matching = {{')', '('}, {']', '['}, {'}', '{'}};

    for (char ch : rak) {
        if (std::find(opening.begin(), opening.end(), ch) != opening.end()) {
            stack.push_back(ch);
        } else if (std::find(closing.begin(), closing.end(), ch) != closing.end()) {
            if (stack.empty()) {
                return false;
            }
            if (stack.back() == matching[ch]) {
                stack.pop_back();
            } else {
                return false;
            }
        }
    }

    return stack.empty();
}
